package com.juitar.chordfinder;

import java.util.List;
import javax.swing.table.AbstractTableModel;

import com.juitar.base.Fingering;

/**
 * @author SKopylov
 */
public class FingeringTableModel extends AbstractTableModel {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4933389841255332285L;
	int _columns;
	List<Fingering> _list;
	
	public FingeringTableModel(List<Fingering> list, int columns) {
		_list = list;
		_columns = columns;
	}


	public void setColumns(int col) {
		_columns = col;
		fireTableStructureChanged();
	}

	/**
	 * @see javax.swing.table.TableModel#getColumnCount()
	 */
	public int getColumnCount() {
		return _columns;
	}

	/**
	 * @see javax.swing.table.TableModel#getRowCount()
	 */
	public int getRowCount() {
		if (_list.size() % _columns == 0) {
			return _list.size() / _columns;
		} else {
			return _list.size() / _columns + 1;
		}
	}

	/**
	 * @see javax.swing.table.TableModel#getValueAt(int, int)
	 */
	public Object getValueAt(int rowIndex, int columnIndex) {
		int idx = rowIndex*_columns + columnIndex;
		if (idx < _list.size()) {
			return _list.get(idx);
		}
		return null;
	}
        
        
        public Class<Fingering> getColumnClass(int idx) {
            return Fingering.class;
        }
	/**
	 * @see javax.swing.table.TableModel#getColumnName(int)
	 */
	public String getColumnName(int columnIndex) {
		return null;
	}

}
